{extend name="common/base" /}
{block name='title'}新增模拟真题{/block}

{block name="body"}
    <article class="Hui-admin-page-container">
        <form class="form form-horizontal" id="form-article-add">
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>模拟真题名称：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="detail_title" name="detail_title">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>题库名称：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <select class="input-text" name="cate" id="cate">
                        {foreach $cates as $k=>$v}
                        <option value="{$v['id']}">{$v['cate_title']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>试题类型：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <select class="input-text" name="chapter_type" id="chapter_type">
                        <option value="2">模拟试题</option>
                        <option value="3">历年真题</option>
                    </select>
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*(年)</span>年份：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="number" class="input-text" value="0" placeholder="" id="chapter_year" name="chapter_year">
                </div>
            </div>

            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分数：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="number" class="input-text" value="0" placeholder="" id="chapter_score" name="chapter_score">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*(分钟)</span>时长：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="number" class="input-text" value="0" placeholder="" id="chapter_time" name="chapter_time">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>题数：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="number" class="input-text" value="0" placeholder="" id="chapter_number" name="chapter_number">
                </div>
            </div>
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>介绍：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <textarea class="input-text" id="chapter_introduce" name="chapter_introduce"></textarea>
                </div>
            </div>

            
            <div class="row clearfix">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>排序值：</label>
                <div class="form-controls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="0" placeholder="" id="articleSort" name="sort">
                </div>
            </div>

            <div class="row clearfix">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
                    <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </div>
        </form>
    </article>
    <input name="uploadImage" type="hidden" value="{:url('upload/uploadImage')}">
    <input name="image" type="hidden" >
    <input name="thumb" type="hidden" >

{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="__JS__/main.js"></script>
<script type="text/javascript">
    $(function(){
        // 复选框样式
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        // 是否评论
        $('#articleComment').on('ifChecked', function(event){
            $("#comment-datetime-start,#comment-datetime-end").attr("disabled",false).removeClass("disabled");
        });
        $('#articleComment').on('ifUnchecked', function(event){
            $("#comment-datetime-start,#comment-datetime-end").attr("disabled",true).addClass("disabled");
        });

        
        // 班级计划摘要
        $(".textarea-article").Huitextarealength({
            minlength: 10,
            maxlength: 500
        });

        // 表单提交验证
        $("#form-article-add").validate({
            rules: {
                title: {
                    required: true,
                },

            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function(form){
                var url = "{:url('chapter_detail/add_one')}";
                var detail_title = $("input[name='detail_title']").val();
                var sort = $("input[name='sort']").val();
                var cate = $("#cate").val();
                var chapter_type = $("#chapter_type").val();
                var chapter_number = $("#chapter_number").val();
                var chapter_time = $("#chapter_time").val();
                var chapter_score = $("#chapter_score").val();
                var chapter_year = $("#chapter_year").val();
                var chapter_introduce = $("#chapter_introduce").val();


                $.ajax({
                    url : url ,
                    type : 'post',
                    dataType : 'json',
                    data : {
                        detail_title : detail_title,
                        sort : sort,
                        cate : cate,
                        chapter_type : chapter_type,
                        chapter_number : chapter_number,
                        chapter_time : chapter_time,
                        chapter_score : chapter_score,
                        chapter_year : chapter_year,
                        chapter_introduce : chapter_introduce,
                    },
                    success :function(ret){
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                //$(form).ajaxSubmit();
            }
        });
    });
    
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}